package jdbc;

import util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author oldliu
 * @since 1.0
 */
public class JdbcTest4 {
    public static void main(String[] args) {
        //String sql="select * from s_student where ?=?";
        //ps.setString(1,"fromcity")
        //ps.setString（2，“hefei");
        String sql="select * from s_student order by stuno desc";
        Connection connection = DBUtil.getConnection();

        PreparedStatement ps = null;
        ResultSet rs=null;
        try {
            ps=connection.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);

             rs = ps.executeQuery();
             for(int i=1;i<=10;i++){
                 rs.next();
             }
            System.out.println("第十条数据:");
            System.out.println(rs.getLong("stuno")+","+rs.getString("sname")+","+rs.getDate("enterdate"));

            rs.previous();
            rs.previous();
            System.out.println("第八条数据：");
            System.out.println(rs.getLong("stuno")+","+rs.getString("sname")+","+rs.getDate("enterdate"));
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(rs,ps,connection);
        }

    }
}
